home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b14
/
Interface
/
AboutBox.c
next >
Wrap
Text File
|
1996-04-12
|
7KB
|
330 lines
/*****
*
* AboutBox.c
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995,1996 by Grant Neufeld
* grant@acm.com
* http://arpp.carleton.ca/grant/mac/grantscgi/
*
*****/
#include "MyConfiguration.h"
#if kCompileWithForeground
#include "compiler_stuff.h"
/* InternetConfig is not supported with Symantec PPC compiler, yet */
#if __SC__
#ifdef kCompileWithAboutURL
#undef kCompileWithAboutURL
#define kCompileWithAboutURL 0
#endif
#endif
#if kCompileWithAboutURL
#include <ICAPI.h>
#endif
#include "constants.h"
#include "globals.h"
#include "DebugUtil.h"
#include "IconUtil.h"
#include "StringUtil.h"
#include "WindowInt.h"
#include "AboutBox.h"
/*** LOCAL VARIABLES ***/
static DialogPtr vAboutBoxDialog;
static Handle vAboutIconSuiteHdl;
static UserItemUPP vAboutIconUPP;
#if kCompileWithAboutURL
static UserItemUPP vAboutURLUPP;
static Str255 vAboutBoxURL;
#endif
/*** LOCAL CONSTANTS ***/
#define kriAboutBoxAppIcon 2
#define kriAboutBoxURL 3
/*** LOCAL PROTOTYPES ***/
pascal void aboutBoxAppIcon ( DialogPtr, short );
#if kCompileWithAboutURL
pascal void aboutBoxURL ( DialogPtr, short );
ICError URLDownload ( StringPtr );
#endif
/*** FUNCTIONS ***/
#pragma segment Startup
/* initialize the variables used for the about box */
void
AboutBoxInit ( void )
{
vAboutBoxDialog = NULL;
vAboutIconSuiteHdl = NULL;
vAboutIconUPP = NULL;
#if kCompileWithAboutURL
vAboutURLUPP = NULL;
GetIndString ( vAboutBoxURL, krURLStrings, 1 );
#endif
} /* AboutBoxInit */
#pragma segment Utilities
/* open the about box dialog window */
void
AboutBoxOpen ( void )
{
short itemType;
Handle item;
Rect box;
GrafPtr savePort;
if ( vAboutBoxDialog == NULL )
{
vAboutBoxDialog = GetNewDialog ( kAboutBoxDLOG, NULL, (WindowPtr)-1L );
if ( vAboutBoxDialog != nil )
{
WindowNewSetInfo ( vAboutBoxDialog, Window_about, false, nil );
if ( vAboutIconUPP == NULL )
{
vAboutIconUPP = NewUserItemProc ( aboutBoxAppIcon );
}
/* install the drawing procedure for the application icon user item */
GetDialogItem ( vAboutBoxDialog, kriAboutBoxAppIcon, &itemType, &item, &box );
SetDialogItem ( vAboutBoxDialog, kriAboutBoxAppIcon, itemType, (Handle)vAboutIconUPP, &box );
#if kCompileWithAboutURL
if ( vAboutURLUPP == NULL )
{
vAboutURLUPP = NewUserItemProc ( aboutBoxURL );
}
/* install the drawing procedure for the application icon user item */
GetDialogItem ( vAboutBoxDialog, kriAboutBoxURL, &itemType, &item, &box );
SetDialogItem ( vAboutBoxDialog, kriAboutBoxURL, itemType, (Handle)vAboutURLUPP, &box );
#endif /* kCompileWithAboutURL */
}
if ( vAboutBoxDialog != NULL )
{
/* set the ^0 parameter to be the version string */
ParamText ( gVersionStr, NULL, NULL, NULL );
/* change the dialog port font to Geneva */
GetPort ( &savePort );
SetPort ( (GrafPtr)vAboutBoxDialog );
TextFont ( geneva );
SetPort ( savePort );
}
}
/* display the dialog window and bring it to front */
if ( vAboutBoxDialog != NULL )
{
ShowWindow ( vAboutBoxDialog );
SelectWindow ( vAboutBoxDialog );
}
} /* AboutBoxOpen */
/* update the contents of the about box dialog window */
void
AboutBoxUpdate ( void )
{
my_assert ( vAboutBoxDialog != NULL, "\pAboutBoxUpdate: vAboutBoxDialog is NULL" );
/* set the dialog strings */
ParamText ( gVersionStr, NULL, NULL, NULL );
/* draw the dialog */
DrawDialog ( vAboutBoxDialog );
} /* AboutBoxUpdate */
/* close the about box window */
void
AboutBoxClose ( void )
{
windowInfoHdl dlogWindInfo;
my_assert ( vAboutBoxDialog != NULL, "\pAboutBoxClose: vAboutBoxDialog is NULL" );
dlogWindInfo = (windowInfoHdl) GetWRefCon ( (WindowRef)vAboutBoxDialog );
if ( dlogWindInfo != NULL )
{
DisposeHandle ( (Handle)dlogWindInfo );
}
DisposeDialog ( vAboutBoxDialog );
vAboutBoxDialog = NULL;
} /* AboutBoxClose */
/* Handle events in the about box */
Boolean
AboutHandleEvent ( EventRecord *theEvent, DialogPtr theDialog, short itemHit )
{
if ( theDialog == vAboutBoxDialog )
{
/* if it's the about box dialog, handle the event */
switch ( theEvent->what )
{
case mouseDown:
switch ( itemHit )
{
#if kCompileWithAboutURL
case kriAboutBoxURL :
URLDownload ( vAboutBoxURL );
break;
#endif
}
break;
case mouseUp:
/* don't do anything */
break;
}
return true;
}
else
{
return false;
}
} /* */
/* Draw the application icon using the ICN# or a color icon resource */
pascal void
aboutBoxAppIcon ( DialogPtr theDialog, short theItem )
{
short itemType;
Rect itemRect;
Handle itemHandle;
PenState curPen;
WindowPtr oldPort;
GetDItem ( theDialog, theItem, &itemType, &itemHandle, &itemRect );
GetPort ( &oldPort );
SetPort ( (GrafPtr)theDialog );
GetPenState ( &curPen );
PenNormal ();
IconDrawFromFamily ( kApplicationIconSuite, &itemRect, &vAboutIconSuiteHdl );
SetPenState ( &curPen );
SetPort ( oldPort );
} /* aboutBoxAppIcon */
#pragma mark -
#if kCompileWithAboutURL
/* Draw the URL string */
pascal void
aboutBoxURL ( DialogPtr theDialog, short theItem )
{
short itemType;
Rect itemRect;
Handle itemHandle;
PenState curPen;
WindowPtr oldPort;
short oldFont;
short oldSize;
short oldFace;
RGBColor oldColor;
RGBColor blueColor;
GetDItem ( theDialog, theItem, &itemType, &itemHandle, &itemRect );
GetPort ( &oldPort );
SetGrafPortOfDialog ( theDialog );
oldFont = oldPort->txFont;
oldSize = oldPort->txSize;
oldFace = oldPort->txFace;
GetForeColor ( &oldColor );
GetPenState ( &curPen );
PenNormal ();
/* set the text format */
TextFont ( geneva );
TextSize ( 9 );
TextFace ( underline );
blueColor.red = nil;
blueColor.green = nil;
blueColor.blue = 0xFFFF;
RGBForeColor ( &blueColor );
/* draw the string */
StringDrawInRect ( vAboutBoxURL, itemRect );
RGBForeColor ( &oldColor );
SetPenState ( &curPen );
TextFace ( oldFace );
TextSize ( oldSize );
TextFont ( oldFont );
SetPort ( oldPort );
} /* aboutBoxURL */
/* Note that this routine can only succeed if Internet Config 1.1 (or better) is
installed on this Mac. Version 1.0 does not support the ICLaunchURL call. */
ICError
URLDownload ( StringPtr theURL )
{
ICError theErr;
ICInstance ICInst;
long SelStart;
long SelEnd;
theErr = ICStart ( &ICInst, kMyCreatorType );
if ( theErr == noErr )
{
theErr = ICFindConfigFile ( ICInst, nil, NULL );
if ( theErr == noErr )
{
SelStart = nil;
SelEnd = *theURL;
theErr = ICLaunchURL ( ICInst, "\p", (Ptr)(theURL + 1), *theURL, &SelStart, &SelEnd );
}
ICStop ( ICInst );
}
if ( theErr != noErr )
{
SysBeep ( 1 );
}
return theErr;
} /* URLDownload */
#endif /* kCompileWithAboutURL */
#endif /* kCompileWithForeground */
/***** EOF *****/